 /* 
 * File:   Dimension2D.cpp
 * Author: josep
 * 
 * Created on 25 / desembre / 2010, 10:47
 */

#include "c2DArea.h"
#include "Globals.h"

c2DArea::c2DArea() {
}

c2DArea::~c2DArea() {
}

void c2DArea::Init(float minX, float minY, float width, float height, float speedX, float speedY){
    iniPointX=minX;
    iniPointY=minY;
    this->width = width;
    this->height = height;
    this->speedX=speedX;
    this->speedY=speedY;
}

int c2DArea::GetIntersectionType(c2DArea* Area){
    int ret=0;
    if(this->minPointY()<Area->maxPointY()
            && Area->maxPointY()<this->maxPointY()
            && Area->minPointX()<=this->maxPointX()
            && Area->maxPointX()>=this->minPointX()){
        ret+=INCLUDE_NORTH;
        //cout << "c. N., ";
    }
    if(this->minPointY()<Area->minPointY()
            && Area->minPointY()<this->maxPointY()
            && Area->minPointX()<=this->maxPointX()
            && Area->maxPointX()>=this->minPointX()){
        ret+=INCLUDE_SOUTH;
        //cout << "c. S., ";
    }
    if(this->minPointX()<Area->minPointX()
            && Area->minPointX()<this->maxPointX()
            && Area->minPointY()<=this->maxPointY()
            && Area->maxPointY()>=this->minPointY()){
        ret+=INCLUDE_EAST;
        //cout << "c. E., ";
    }
    if(this->minPointX()<Area->maxPointX()
            && Area->maxPointX()<this->maxPointX()
            && Area->minPointY()<=this->maxPointY()
            && Area->maxPointY()>=this->minPointY()){
        ret+=INCLUDE_WEST;
        //cout << "c. E., ";
    }
    return ret;
}

bool c2DArea::hasIncluded(int inclusionValue, int InclusionType){
    return (inclusionValue&InclusionType);
}

bool c2DArea::hasIncluded( c2DArea *Area, int InclusionType){
    return hasIncluded(GetIntersectionType(Area), InclusionType);
}

int c2DArea::minPointX(){
    return iniPointX;
}

int c2DArea::minPointY(){
    return iniPointY;
}

int c2DArea::maxPointX(){
    return minPointX()+width;
}

int c2DArea::maxPointY(){
    return minPointY()+height;
}
float c2DArea::GetSpeedX() const {
    return speedX;
}
float c2DArea::GetSpeedY() const {
    return speedY;
}

void c2DArea::SetPos(float minX, float minY){
    iniPointX=minX;
    iniPointY=minY;
}
